{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Using dummy estimators to compare results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DummyRegressor(constant=None, quantile=None, strategy='mean')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.datasets import make_regression, make_classification\n",
    "\n",
    "X, y = make_regression()\n",
    "from sklearn import dummy\n",
    "dumdum = dummy.DummyRegressor()\n",
    "dumdum.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 21.44650731,  21.44650731,  21.44650731,  21.44650731,  21.44650731])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dumdum.predict(X)[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "strategy: mean 21.446507307,21.446507307,21.446507307,21.446507307,21.446507307\n",
      "strategy: median 24.1999513052,24.1999513052,24.1999513052,24.1999513052,24.1999513052\n",
      "strategy: constant 10.0,10.0,10.0,10.0,10.0\n"
     ]
    }
   ],
   "source": [
    "predictors = [(\"mean\", None),\n",
    "(\"median\", None),\n",
    "(\"constant\", 10)]\n",
    "for strategy, constant in predictors:\n",
    "      dumdum = dummy.DummyRegressor(strategy=strategy,\n",
    "      constant=constant)\n",
    "      dumdum.fit(X, y)\n",
    "      print \"strategy: {}\".format(strategy), \",\".join(map(str, dumdum.predict(X)[:5]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "strategy: constant 0,0,0,0,0\n",
      "strategy: stratified 0,1,0,0,1\n",
      "strategy: uniform 0,0,0,1,1\n",
      "strategy: most_frequent 0,0,0,0,0\n"
     ]
    }
   ],
   "source": [
    "predictors = [(\"constant\", 0),(\"stratified\", None),(\"uniform\", None),(\"most_frequent\", None)]\n",
    "#We'll also need to create some classification data:\n",
    "X, y = make_classification()\n",
    "for strategy, constant in predictors:\n",
    "     dumdum = dummy.DummyClassifier(strategy=strategy,\n",
    "     constant=constant)\n",
    "     dumdum.fit(X, y)\n",
    "     print \"strategy: {}\".format(strategy), \",\".join(map(str,dumdum.predict(X)[:5]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DummyClassifier(constant=None, random_state=None, strategy='most_frequent')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X, y = make_classification(20000, weights=[.95, .05])\n",
    "dumdum = dummy.DummyClassifier(strategy='most_frequent')\n",
    "dumdum.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.94585\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "print accuracy_score(y, dumdum.predict(X))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
